<?php
class Laporan extends Controller{
	function laporan(){
		parent::Controller();
		$this->load->model('analisa_model');
		$this->load->model('laporan_model');
	}
	
	var $title = 'laporan';
	var $batas = 10;
	
	function bulan1(){//untuk laporan 1 bulanan
		if($this->session->userdata('login') == TRUE){
			$data['title'] = $this->title;
			$data['h2_title'] = 'Laporan Hasil Per 1 Bulan';
			$data['main'] = 'laporan/laporan';
		
			//pagination
			//set pagination
			$config['base_url'] = site_url('laporan/bulan1');
			$config['total_rows'] = $this->laporan_model->count_table_1bln();
			$config['per_page'] = $this->batas;
			$this->pagination->initialize($config);
			$data['pagination'] = $this->pagination->create_links();
			//setting tabel
			$tmpl = array( 'table_open'  => '<table border="0" cellpadding="0" cellspacing="0">',
						'row_alt_start'  => '<tr class="zebra">',
						'row_alt_end'    => '</tr>');
					
			$this->table->set_template($tmpl);
		
			$this->table->set_empty('&nbsp;');
			$this->table->set_heading('No','Cabang','Periode','Hasil','Bobot','Waktu Analisa');
			//tabel untuk superadmin
			if($this->session->userdata('id_usergroup') == 6){
				$ambil = $this->laporan_model->get_1bln();
				if(isset($ambil)){
					$n = 1;
				
					foreach($ambil as $row){
						$this->table->add_row($n++, $row->cabang, $row->Periode, $row->HASIL, $row->bobot, $row->WAKTU);
					}
					$data['table'] = $this->table->generate();
				}
				else{
					$this->session->set_flashdata('message', 'Maaf, Data tidak ditemukan');
				}
			}
			
			//tabel untuk akuntan
			if($this->session->userdata('id_usergroup') == 2){
				$id_cab = $this->session->userdata('id_cabang');
				$ambil = $this->laporan_model->get_1bln_by_id($id_cab);
				if(isset($ambil)){
					$n = 1;
				
					foreach($ambil as $row){
						$this->table->add_row($n++, $row->cabang, $row->Periode, $row->HASIL, $row->bobot, $row->WAKTU);
					}
				$data['table'] = $this->table->generate();
				}
				else{
					$this->session->set_flashdata('message', 'Maaf, Data tidak ditemukan');
				}
			}
		
			$this->load->view('base', $data);
		}
		else{
				redirect('home');
		}	
		
	}
	
	function bulan3(){//untuk laporan 3 bulanan
		if($this->session->userdata('login') == TRUE){
			$data['title'] = $this->title;
			$data['h2_title'] = 'Laporan Hasil Per 3 Bulan';
			$data['main'] = 'laporan/laporan';
		
			//pagination
			//set pagination
			$config['base_url'] = site_url('laporan/bulan3');
			$config['total_rows'] = $this->laporan_model->count_table_3bln();
			$config['per_page'] = $this->batas;
			$this->pagination->initialize($config);
			$data['pagination'] = $this->pagination->create_links();
			//setting tabel
			$tmpl = array( 'table_open'  => '<table border="0" cellpadding="0" cellspacing="0">',
						'row_alt_start'  => '<tr class="zebra">',
						'row_alt_end'    => '</tr>');
					
			$this->table->set_template($tmpl);
		
			$this->table->set_empty('&nbsp;');
			$this->table->set_heading('No','Cabang','Periode','Hasil','Bobot','Waktu Analisa');
			//tabel untuk superadmin
			if($this->session->userdata('id_usergroup') == 6){
				$ambil = $this->laporan_model->get_3bln();
				if(isset($ambil)){
					$n = 1;
				
					foreach($ambil as $row){
						$this->table->add_row($n++, $row->cabang, $row->Periode, $row->HASIL, $row->bobot, $row->WAKTU);
					}
					$data['table'] = $this->table->generate();
				}
				else{
					$this->session->set_flashdata('message', 'Maaf, Data tidak ditemukan');
				}
			}
			
			//tabel untuk akuntan
			if($this->session->userdata('id_usergroup') == 2){
				$id_cab = $this->session->userdata('id_cabang');
				$ambil = $this->laporan_model->get_3bln_by_id($id_cab);
				if(isset($ambil)){
					$n = 1;
				
					foreach($ambil as $row){
						$this->table->add_row($n++, $row->cabang, $row->Periode, $row->HASIL, $row->bobot, $row->WAKTU);
					}
				$data['table'] = $this->table->generate();
				}
				else{
					$this->session->set_flashdata('message', 'Maaf, Data tidak ditemukan');
				}
			}
		
			$this->load->view('base', $data);
		}
		else{
				redirect('home');
		}	
		
	}
	
	function bulan6(){//untuk laporan 6 bulanan
		if($this->session->userdata('login') == TRUE){
			$data['title'] = $this->title;
			$data['h2_title'] = 'Laporan Hasil Per 6 Bulan';
			$data['main'] = 'laporan/laporan';
		
			//pagination
			//set pagination
			$config['base_url'] = site_url('laporan/bulan6');
			$config['total_rows'] = $this->laporan_model->count_table_6bln();
			$config['per_page'] = $this->batas;
			$this->pagination->initialize($config);
			$data['pagination'] = $this->pagination->create_links();
			//setting tabel
			$tmpl = array( 'table_open'  => '<table border="0" cellpadding="0" cellspacing="0">',
						'row_alt_start'  => '<tr class="zebra">',
						'row_alt_end'    => '</tr>');
					
			$this->table->set_template($tmpl);
		
			$this->table->set_empty('&nbsp;');
			$this->table->set_heading('No','Cabang','Periode','Hasil','Bobot','Waktu Analisa');
		
			//tabel untuk superadmin
			if($this->session->userdata('id_usergroup') == 6){
				$ambil = $this->laporan_model->get_6bln();
				if(isset($ambil)){
					$n = 1;
				
					foreach($ambil as $row){
						$this->table->add_row($n++, $row->cabang, $row->Periode, $row->HASIL, $row->bobot, $row->WAKTU);
					}
					$data['table'] = $this->table->generate();
				}
				else{
					$this->session->set_flashdata('message', 'Maaf, Data tidak ditemukan');
				}
			}
			
			//tabel untuk akuntan
			if($this->session->userdata('id_usergroup') == 2){
				$id_cab = $this->session->userdata('id_cabang');
				$ambil = $this->laporan_model->get_6bln_by_id($id_cab);
				if(isset($ambil)){
					$n = 1;
				
					foreach($ambil as $row){
						$this->table->add_row($n++, $row->cabang, $row->Periode, $row->HASIL, $row->bobot, $row->WAKTU);
					}
				$data['table'] = $this->table->generate();
				}
				else{
					$this->session->set_flashdata('message', 'Maaf, Data tidak ditemukan');
				}
			}
		
			$this->load->view('base', $data);
		}
		else{
				redirect('home');
		}	
		
	}
	
	function bulan12(){//untuk laporan 12 bulanan
		if($this->session->userdata('login') == TRUE){
			$data['title'] = $this->title;
			$data['h2_title'] = 'Laporan Hasil Per 12 Bulan';
			$data['main'] = 'laporan/laporan';
		
			//pagination
			//set pagination
			$config['base_url'] = site_url('laporan/bulan12');
			$config['total_rows'] = $this->laporan_model->count_table_12bln();
			$config['per_page'] = $this->batas;
			$this->pagination->initialize($config);
			$data['pagination'] = $this->pagination->create_links();
			//setting tabel
			$tmpl = array( 'table_open'  => '<table border="0" cellpadding="0" cellspacing="0">',
						'row_alt_start'  => '<tr class="zebra">',
						'row_alt_end'    => '</tr>');
					
			$this->table->set_template($tmpl);
		
			$this->table->set_empty('&nbsp;');
			$this->table->set_heading('No','Cabang','Periode','Hasil','Bobot','Waktu Analisa');
		
			//tabel untuk superadmin
			if($this->session->userdata('id_usergroup') == 6){
				$ambil = $this->laporan_model->get_12bln();
				if(isset($ambil)){
					$n = 1;
				
					foreach($ambil as $row){
						$this->table->add_row($n++, $row->cabang, $row->Periode, $row->HASIL, $row->bobot, $row->WAKTU);
					}
					$data['table'] = $this->table->generate();
				}
				else{
					$this->session->set_flashdata('message', 'Maaf, Data tidak ditemukan');
				}
			}
			
			//tabel untuk akuntan
			if($this->session->userdata('id_usergroup') == 2){
				$id_cab = $this->session->userdata('id_cabang');
				$ambil = $this->laporan_model->get_12bln_by_id($id_cab);
				if(isset($ambil)){
					$n = 1;
				
					foreach($ambil as $row){
						$this->table->add_row($n++, $row->cabang, $row->Periode, $row->HASIL, $row->bobot, $row->WAKTU);
					}
				$data['table'] = $this->table->generate();
				}
				else{
					$this->session->set_flashdata('message', 'Maaf, Data tidak ditemukan');
				}
			}
		
			$this->load->view('base', $data);
		}
		else{
				redirect('home');
		}	
		
	}
}
?>